{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "22de2342-b5a3-4be7-ad1b-d2528f3342d7",
   "metadata": {},
   "source": [
    "# Category Breakdown Bar Chart\n",
    "\n",
    "A grouped bar chart that shows how each species of penguin is distributed across different islands. This example uses the `penguins` dataset from hvplot's built-in sample data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b69391d9-10da-4e80-ad16-335188c50f6c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.pandas  # noqa\n",
    "\n",
    "df = hvplot.sampledata.penguins('pandas')\n",
    "grouped = df.groupby(['species', 'island'], observed=True).size().reset_index(name='count')\n",
    "\n",
    "grouped.hvplot.bar(\n",
    "    x='species',\n",
    "    y='count',\n",
    "    by='island',\n",
    "    title='Category Breakdown Bar Chart (Bokeh)',\n",
    "    xlabel='Species',\n",
    "    ylabel='Count',\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1b7aaf92-b504-411b-b449-e5fd3af088bd",
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.pandas  # noqa\n",
    "hvplot.extension('matplotlib')\n",
    "\n",
    "df = hvplot.sampledata.penguins('pandas')\n",
    "grouped = df.groupby(['species', 'island'], observed=True).size().reset_index(name='count')\n",
    "\n",
    "grouped.hvplot.bar(\n",
    "    x='species',\n",
    "    y='count',\n",
    "    by='island',\n",
    "    title='Category Breakdown Bar Chart (Matplotlib)',\n",
    "    xlabel='Species',\n",
    "    ylabel='Count',\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "221825d9-885f-4263-a0d4-fd3501e7b3df",
   "metadata": {},
   "outputs": [],
   "source": [
    "grouped"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "80ed7ac9-84f7-489f-9ee8-f83527987167",
   "metadata": {},
   "source": [
    ":::{seealso}\n",
    "- [Bar Plots reference documentation](../../ref/api/manual/hvplot.hvPlot.bar.ipynb).\n",
    ":::"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
